﻿using System;//
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Globalization;
using System.Threading;
using FormattingLib;

namespace Test.Formatting
{ 
    [TestClass]
    public class NumberFormattingRoundingTest1
    {



        [TestMethod]
        public void RoundTest1()
        {
            // Frameworkbug ??????????????????????
            var res1 = Math.Round(1.5, 0, MidpointRounding.AwayFromZero); // gives 2
            var res2 = Math.Round(1.5, 0, MidpointRounding.ToEven); // gives 2

            var res3 = Math.Round(2.5, 0, MidpointRounding.AwayFromZero); // gives 3
            var res4 = Math.Round(2.5, 0, MidpointRounding.ToEven); // gives 2

            // Frameworkbug ??????????????????????
            var res5 = Math.Round(3.5, 0, MidpointRounding.AwayFromZero); // gives 4
            var res6 = Math.Round(3.5, 0, MidpointRounding.ToEven); // gives 4

        }

             
        [TestMethod]
        public void GetRoundedNumber_Test1()
        {
            ///                        a=-2.7  b=-0.5  c=0.3  d=1.5  e=2.8
            /// =====================  ======  ======  =====  =====  =====
            /// Floor                    -3      -1      0      1      2
            /// Ceiling                  -2       0      1      2      3
            /// Truncate                 -2       0      0      1      2
            /// Round (ToEven)           -3       0      0      2      3
            /// Round (AwayFromZero)     -3      -1      0      2      3


            double result = -1;

            
            // Round with the default of 3 decimals 
            // and RoundingType Round (RoundAwayFromZero).
            result = NumberFormatting.GetRoundedNumber(1.5555);
            Assert.AreEqual(1.556, result);
            

           
            //Floor
            result = NumberFormatting.GetRoundedNumber(1.5, RoundingType.Floor);
            Assert.AreEqual(1, result);

            result = NumberFormatting.GetRoundedNumber(2.8, RoundingType.Floor);
            Assert.AreEqual(2, result);
            



            //Ceiling
            result = NumberFormatting.GetRoundedNumber(0.3, RoundingType.Ceiling);
            Assert.AreEqual(1, result);

            result = NumberFormatting.GetRoundedNumber(1.5, RoundingType.Ceiling);
            Assert.AreEqual(2, result);

            result = NumberFormatting.GetRoundedNumber(2.8, RoundingType.Ceiling);
            Assert.AreEqual(3, result);
                      



            //RoundAwayFromZero with some different decimals
            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 10);
            Assert.AreEqual(1.5555, result);

            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 4);
            Assert.AreEqual(1.5555, result);

            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 3);
            Assert.AreEqual(1.556, result);

            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 2);
            Assert.AreEqual(1.56, result);

            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 1);
            Assert.AreEqual(1.6, result);

            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round, 0);
            Assert.AreEqual(2, result);




            //RoundAwayFromZero with default of 3 decimals
            result = NumberFormatting.GetRoundedNumber(1.5555, RoundingType.Round);
            Assert.AreEqual(1.556, result);


        }





    }
}

